﻿function loadTree() {
    var setting = {
        data:{
            simpleData:{
                enable:true,
                idKey:"id",
                pIdKey:"pId",
                rootPId: null
            }
        },
        view: {
            showLine: true, //是否显示节点间的连线
            showIcon: true
        },
        callback: {
            onClick:loadRightContent  //点击节点，加载右边的内容
        }
        //check: {
        //    autoCheckTrigger: true,
        //    chkboxType: { "Y": "ps", "N": "ps" },
        //    chkStyle: "checkobx",
        //    enable: true,
        //    radioType: "level",//"all"
        //}
    };
    var treeNodes = $.parseJSON($("#nodesJson").val());

    var zTree = $.fn.zTree.init($("#tree"),setting, treeNodes);
    $("#nodesJson").remove();

    loadRightContent(null,"tree",zTree.getNodes()[0], false);
}

function loadRightContent(event, treeId, treeNode) {
    var treeObj = $.fn.zTree.getZTreeObj(treeId);

    //选中该节点获得焦点
    treeObj.selectNode(treeNode, false);

    //加载右边的内容
    var selector = "#subContent .rightContent";
    //根据当前选中的栏目获取要加载端url
    var url = $("#subNav span.selectedNav").attr("data-href");
    //取得筛选条件
    url = url + "?id=" + treeNode.id;
    ajaxLoad(selector, url);
}